package com.mutouren.web;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.mutouren.common.exception.ExceptionUtils;
import com.mutouren.common.log.LogAlias;
import com.mutouren.common.log.LogManager;
import com.mutouren.common.log.Logger;

@ControllerAdvice
public class AdviceExceptionHandler {
	
	private static Logger errorLogger = LogManager.getLogger(LogAlias.SystemError.name());

	@ExceptionHandler(Throwable.class)
	public void doError(Throwable t, HttpServletResponse response) {
		try {
			response.setContentType("text/plain;charset=utf-8");
			response.getWriter().write("mtr异常: " + t.getMessage());			
		} catch (Throwable tt) {			
			throw ExceptionUtils.doUnChecked(tt);
		} finally {
			errorLogger.error("mtr异常", t);
		}
	}
}
